//pages/register/register.js
Page({
  data: {
    data: '2010-09-26',
    items: [{ name: '篮球', value: '篮球' },
    { name: '足球', value: '足球' },
    { name: '羽毛球', value: '羽毛球' },
    { name: '乒乓球', value: '乒乓球' },
    { name: '唱歌', value: '唱歌' },
    { name: '跳舞', value: '跳舞' },
    { name: '看电影', value: '看电影' },
    { name: '看书', value: '看书' },
    { name: '美食', value: '美食' },],
    classArray: ["选项一", "选项二"],
    index: 0
  },

  formSubmit: function (e) {
    console.log('form发生了submit事件,提交数据:', e.detail.value);

    if (e.detail.value.password != e.detail.value.password2) {
      wx.showToast({
        title: "两次密码不一致",
        image: '/assets/images/warn.png',
      });
      return;
    }
    var reg = /^1[3|4|5|7|8][0-9]{9}$/;
    var phone = e.detail.value.phone;
    var flag = reg.test(phone);

    if (!flag) {
      wx.showToast({
        title: "请输入正确的手机号",
        image: '/assets/images/warn.png',
      });
      return;
    }

    wx.request({
      url: 'https://www.wxabc.xyz/wxserver/userAdd.php',
      data: {
        'userid': e.detail.value.userid,
        'username': e.detail.value.username,
        'password': e.detail.value.password,
        'sex': e.detail.value.sex,
        'phone': e.detail.value.phone,
        'littleclass': e.detail.value.littleclass,
        'brithday': e.detail.value.brithday,
        'interest': e.detail.value.interest,
        'suggest': e.detail.value.suggest,
      },

      method: "POST",
      header: {
        'content-type': 'application/w-xxx-form-urlencoded'
      },
      success: function (res) {
        console.log("返回值:");
        if (res.data.state == 1) {
          wx.showToast({
            title: res.data.indexOf,
            icon: 'success'
          });
        } else {
          wx.showToast({
            title: res.data.info,
            icon: 'warn'
          });
        }
      }
    })
  },
  formReset: function () {
    console.log('form发生了reset事件')
  },
  pickerchange: function (e) {
    this.setData({
      data: e.detail.value
    })
  },
})